package com.mes.datasource.service;

import com.mes.datasource.vo.DataSourceVO;
import com.yy.base.common.dao.Dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class DataSourceService {
	@Autowired
	private Dao dao;

	public DataSourceVO getRequestData(String url) {
		String sql = "select * from Emes_Datasource where url = ?";
		DataSourceVO vo = DataSourceVO.create(dao.queryUnique(sql, url));
		vo.setColumns(queryColumn(vo.getId()));
		vo.setParams(queryParams(vo.getId()));
		return vo;
	}

	public List<Map<String, Object>> queryList(String sql, Object ...values) {
		return dao.query(sql, values);
	}

	public List<Map<String, Object>> splitQuery(String sql, Object ...values) {
		return dao.splitQuery(sql, values);
	}

	public Map<String, Object> queryUnique(String sql, Object ...values) {
		return dao.queryUnique(sql, values);
	}

	private List<Map<String, Object>> queryColumn(String id) {
		String sql = "select * from Emes_Datasource_Column where Emes_Datasource_id = ?";
		return dao.query(sql, id);
	}

	private List<Map<String, Object>> queryParams(String id) {
		String sql = "select * from Emes_Datasource_Param where Emes_Datasource_id = ?";
		return dao.query(sql, id);
	}
}